package lar.game.physics;

public class Circle
{
	private final Position position;
	private final double radius;
	
	public Circle(Position position, double radius)
	{
		this.position = position;
		this.radius = radius;
	}
	
	public Position GetPosition()
	{
		return position;
	}
	
	public double GetRadius()
	{
		return radius;
	}
	
	public double StartX()
	{
		return position.PosX() - radius;
	}
	
	public double EndX()
	{
		return position.PosX() + radius;
	}
	
	public double StartY()
	{
		return position.PosY() - radius;
	}
	
	public double EndY()
	{
		return position.PosY() + radius;
	}
	
	public double GetMaxAtX(double x)
	{
		if((position.PosX() - x > radius) || (x - position.PosX() > radius)) return position.PosY();
		double yRoot = x - position.PosX();
		yRoot *= yRoot;
		yRoot = radius * radius - yRoot;
		return position.PosY() + Math.sqrt(yRoot);
	}
	
	public double GetMinAtX(double x)
	{
		if((position.PosX() - x > radius) || (x - position.PosX() > radius)) return position.PosY();
		double yRoot = x - position.PosX();
		yRoot *= yRoot;
		yRoot = radius * radius - yRoot;
		return position.PosY() - Math.sqrt(yRoot);
	}
}
